﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.SQLite;

namespace BuildUtility
{
    class Program
    {
        #region Constants
        private const string USER_DATA_FILE_NAME = "UserData.s3db";
        #endregion

        #region Properties
        #endregion

        #region Events
        #endregion

        #region Constructors
        static void Main(string[] pArgs)
        {
            //System.Diagnostics.Debugger.Launch();

            string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            Environment.CurrentDirectory = Path.GetDirectoryName(assemblyPath);

            if (pArgs.Length < 1)
            {
                string errorMessage =
                    "Invalid arguments: " + Environment.NewLine +
                    "\t1. target path";
                throw new ArgumentException(errorMessage);
            }

            string targetPath = pArgs[0];
            string dataPath = Path.Combine(targetPath, "Data");

            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }

            // without sleep, for some reason directory would not be created if it was deleted in previous step
            System.Threading.Thread.Sleep(1000);

            Directory.CreateDirectory(dataPath);

            string userDataFilePath = Path.Combine(dataPath, USER_DATA_FILE_NAME);
            SQLiteConnection connection = DataAccess.Connect(userDataFilePath);
            DataAccess.CreateUserDataTables(connection);
            DataAccess.Disconnect(connection);

            //Stream stream = File.Create("xxx.txt");
            //TextWriter tw = new StreamWriter(stream);
            //tw.WriteLine(Environment.CurrentDirectory);
            //foreach (string arg in pArgs)
            //{
            //    tw.WriteLine(arg);
            //}
            //tw.Close();
        }
        #endregion

        #region Overriden Methods
        #endregion

        #region Methods

        #endregion

        #region Event Handlers
        #endregion

        #region Inner Classes
        #endregion
    }
}